﻿// Decompiled with JetBrains decompiler
// Type: System.Web.Razor.Parser.SyntaxTree.SpanBuilder
// Assembly: System.Web.Razor, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35
// MVID: 682513D6-F37E-48AC-9909-F3EE103CFF14
// Assembly location: D:\Project\Idea\无人机外网\uav\客户端工程\排查工具\bin\Release\System.Web.Razor.dll

using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Web.Razor.Editor;
using System.Web.Razor.Generator;
using System.Web.Razor.Text;
using System.Web.Razor.Tokenizer.Symbols;

namespace System.Web.Razor.Parser.SyntaxTree
{
  /// <summary>This type/member supports the .NET Framework infrastructure and is not intended to be used directly from your code.Represents the span builder for the syntax tree.</summary>
  public class SpanBuilder
  {
    private IList<ISymbol> _symbols = (IList<ISymbol>) new List<ISymbol>();
    private SourceLocationTracker _tracker = new SourceLocationTracker();

    /// <summary>This type/member supports the .NET Framework infrastructure and is not intended to be used directly from your code.Initializes a new instance of the <see cref="T:System.Web.Razor.Parser.SyntaxTree.SpanBuilder" /> class.</summary>
    /// <param name="original">The original span.</param>
    public SpanBuilder(Span original)
    {
      this.Kind = original.Kind;
      this._symbols = (IList<ISymbol>) new List<ISymbol>(original.Symbols);
      this.EditHandler = original.EditHandler;
      this.CodeGenerator = original.CodeGenerator;
      this.Start = original.Start;
    }

    /// <summary>This type/member supports the .NET Framework infrastructure and is not intended to be used directly from your code.Initializes a new instance of the <see cref="T:System.Web.Razor.Parser.SyntaxTree.SpanBuilder" /> class.</summary>
    public SpanBuilder() => this.Reset();

    /// <summary>This type/member supports the .NET Framework infrastructure and is not intended to be used directly from your code.Gets or sets the source location of the span builder.</summary>
    /// <returns>The source location of the span builder.</returns>
    public SourceLocation Start { get; set; }

    /// <summary>This type/member supports the .NET Framework infrastructure and is not intended to be used directly from your code.Gets or sets the span kind of the span builder.</summary>
    /// <returns>The span kind of the span builder.</returns>
    public SpanKind Kind { get; set; }

    /// <summary>This type/member supports the .NET Framework infrastructure and is not intended to be used directly from your code.Gets the symbols for a generic read-only collection.</summary>
    /// <returns>The symbols for a generic read-only collection.</returns>
    public ReadOnlyCollection<ISymbol> Symbols => new ReadOnlyCollection<ISymbol>(this._symbols);

    /// <summary>This type/member supports the .NET Framework infrastructure and is not intended to be used directly from your code.Gets or sets the span edit handler of the builder.</summary>
    /// <returns>The span edit handler of the builder.</returns>
    public SpanEditHandler EditHandler { get; set; }

    /// <summary>This type/member supports the .NET Framework infrastructure and is not intended to be used directly from your code.Gets or sets the span code generator.</summary>
    /// <returns>The span code generator.</returns>
    public ISpanCodeGenerator CodeGenerator { get; set; }

    /// <summary>This type/member supports the .NET Framework infrastructure and is not intended to be used directly from your code.Resets the span builder.</summary>
    public void Reset()
    {
      this._symbols = (IList<ISymbol>) new List<ISymbol>();
      this.EditHandler = SpanEditHandler.CreateDefault((Func<string, IEnumerable<ISymbol>>) (s => Enumerable.Empty<ISymbol>()));
      this.CodeGenerator = SpanCodeGenerator.Null;
      this.Start = SourceLocation.Zero;
    }

    /// <summary>This type/member supports the .NET Framework infrastructure and is not intended to be used directly from your code.Builds a span builder for this instance.</summary>
    /// <returns>A span builder for this instance.</returns>
    public Span Build() => new Span(this);

    /// <summary>This type/member supports the .NET Framework infrastructure and is not intended to be used directly from your code.Clears the symbols of the span builder.</summary>
    public void ClearSymbols() => this._symbols.Clear();

    /// <summary>This type/member supports the .NET Framework infrastructure and is not intended to be used directly from your code.Accepts the given symbol for the span builder.</summary>
    /// <param name="symbol">The symbol builder.</param>
    public void Accept(ISymbol symbol)
    {
      if (symbol == null)
        return;
      if (this._symbols.Count == 0)
      {
        this.Start = symbol.Start;
        symbol.ChangeStart(SourceLocation.Zero);
        this._tracker.CurrentLocation = SourceLocation.Zero;
      }
      else
        symbol.ChangeStart(this._tracker.CurrentLocation);
      this._symbols.Add(symbol);
      this._tracker.UpdateLocation(symbol.Content);
    }
  }
}
